<?php
// error_reporting(0);
header('Content-Type:text/plain;charset=utf-8');
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'Exception.php';
require 'PHPMailer.php';
require 'SMTP.php';
date_default_timezone_set("PRC");
$user_c = $_GET['user'];
$password_c = $_GET['password'];
$password_c = md5(md5($password_c) . '0000'); //双重md5加密，密钥0000
$email = $_GET['email'];
$timestamp = date("YmdHis");
$active_code = base64_encode($user_c . $password_c . $timestamp);
$host = 'localhost';
$user = 'root';
$password = 'Xiangni365';
$database = 'login';
$con = mysqli_connect($host, $user, $password, $database);
if (!$con) {
    die('Connection Failed!');
}
$check = mysqli_query($con, "SELECT * FROM login_check WHERE user='$user_c'");
if ($check->num_rows != 0) {
    echo ('2');} else {
    $insert = mysqli_query($con, "INSERT INTO login_check (user,nick_name,face_url,password,email,active_code)
        VALUES ('$user_c','$user_c','../upload/$user_c.jpeg','$password_c','$email','$active_code')");
    if ($insert) {
        $mail = new PHPMailer();
        $body = "<h1>账号激活链接为：</h1><a href='http://47.107.66.0/form/php/account_active.php?act=$active_code'>点此激活</a>";
//设置smtp参数
        $mail->IsSMTP();
        $mail->SMTPAuth = true;
        $mail->SMTPKeepAlive = true;
        $mail->SMTPSecure = "ssl";
        $mail->Host = "smtp.qq.com";
        $mail->Port = 465;
//填写你的email账号和密码
        $mail->Username = "cafuchino@vip.qq.com";
        $mail->Password = "aywbqrprjpehbdea"; #注意这里也要填写授权码就是我在上面QQ邮箱开启SMTP中提到的，不能填邮箱登录的密码哦。
        //设置发送方，最好不要伪造地址
        $mail->From = "kirino@cafuchino.cn";
        $mail->FromName = "陌谦";
        $mail->Subject = "请激活你的账号";
        $mail->AltBody = $body;
        $mail->WordWrap = 50; // set word wrap
        $mail->MsgHTML($body);
//设置回复地址
        // $mail->AddReplyTo("kirino@cafuchino.cn","陌谦");
        //添加附件，此处附件与脚本位于相同目录下否则填写完整路径
        //附件的话我就注释掉了
        #$mail->AddAttachment("attachment.jpg");
        #$mail->AddAttachment("attachment.zip");
        //设置邮件接收方的邮箱和姓名
        $mail->AddAddress("$email", "用户");
//使用HTML格式发送邮件
        $mail->IsHTML(true);

//通过Send方法发送邮件
        //根据发送结果做相应处理
        if (!$mail->Send()) {
            echo "Mailer Error:" . $mail->ErrorInfo;} else {echo ('1');}

    } else {
        echo ('0');
    }
}
